package com.xy.system.source;

import com.xy.system.source.act.MysqlAction;
import com.xy.system.source.act.OracleAction;
import com.xy.system.source.act.PostgresAction;
import com.xy.system.source.act.SqlServerAction;
import com.xy.system.source.vo.DataSourceVO;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

public enum DataSourceType {
    //数据库
    sqlserver(new SqlServerAction())
    //数据库
    , mysql(new MysqlAction())
    //数据库
    , oracle(new OracleAction())
    //数据库
    , postgres(new PostgresAction());

    private IDataSourceServer dataSourceServer;

    DataSourceType(IDataSourceServer server) {
        this.dataSourceServer = server;
    }

    public String getServerName() {
        return this.dataSourceServer.getServerName();
    }

    public void fillDbName(DataSourceVO dataSource) {
        this.dataSourceServer.fillDbName(dataSource);
    }

    public Map<String, String> getRemarkNameMap(Connection conn, DataSourceVO dataSource, String tableName) {
        return dataSourceServer.getRemarkNameMap(conn, dataSource, tableName);
    }

    public List<String> getAllTableMap(Connection conn, DataSourceVO dataSource) {
        return dataSourceServer.getAllTableMap(conn, dataSource);
    }

    public static DataSourceType getByCode(String code) {
        return DataSourceType.valueOf(code);
    }

}
